<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
	<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
<script type="text/javascript" src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
   <link href="${approot}/resource/jquery/validate/jquery.validate.css" rel="stylesheet" type="text/css" />
   <link href="${approot}/resource/jquery/validate/style.css" rel="stylesheet" type="text/css" />
   
     <script type="text/javascript">
            /* <![CDATA[ */
            jQuery(function(){
                jQuery("#name").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "用户名不能为空"
                });
                jQuery("#realname").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "真实姓名不能为空"
                });
                jQuery("#yuanpassword").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "原密码不能为空"
                });
                jQuery("#password").validate({
                    expression: "if (VAL.length > 5 && VAL) return true; else return false;",
                    message: "密码不能为空,由大于6位的字母和数字组成"
                });
                jQuery("#repassword").validate({
                    expression: "if ((VAL == jQuery('#password').val()) && VAL) return true; else return false;",
                    message: "两次输入的密码不一致"
                });
                jQuery('#user').validated(function(){
					//alert("通过验证");
					do_edit();
				});
            });
            /* ]]> */
        </script>
        
        <script type="text/javascript">
        function do_edit()
        {   
            var str=$('#user').serializeObject();
            var jsons = $.toJSON(str);
            edit_user(jsons);
        }


        function edit_user(jsons){
 	       $.ajax({
 		   	url:'${approot}/admin/user/edit',
 		   	dataType: 'json',
 		   	contentType: 'application/json',
 			data:jsons,
 			type:'post',
 			beforeSend:function(){
 			  // $('#main').disabled='true';
 			},
 			error:function(request){
 				alert(S);
 			},
 			success:function(data){
 			   if(data.msg=="error")
 			   {
 	 			   alert('原始密码不正确,请重新输入');
 			   }
 			   if(data.msg=="succ")
 			   {
 				  alert('用户信息修改成功');
 				 location.href="${approot}/admin/user/right/${deptid}";
 			   }
 			}
 		   });
 	}
        </script>
        
        
           <script type="text/javascript">
        function checkAll(val){
            //alert(val);
            if(val)
              $('input[name=ids]').each(function(){
                   $(this).attr('checked',true);
              })
             else
            	 $('input[name=ids]').each(function(){
                     $(this).attr('checked',false);
                })  
           }
        
        </script>
   
</head>  
  <body style="background:#E8F5FE; padding:15px 18px;" class="scroll_r">
<div id="right_w"><p>当前位置：系统管理 >>用户修改</p></div>

<form method="post" action="${approot}/admin/user/edit" id="user">
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" class="tab_l">
    <tr>
      <td><b>请按要求填写：</b></td>
      <td align="right">带<span style="color:#ff0000;">*</span>为必填</td>
    </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" id="add_tab">
  <tr>
   <th width="20%"><span style="color:#ff0000; margin:0;">*</span> 用户名：</th>
   <td width="80%"><input type="text" id="name" name="name" value="${user.name}"></td>
  </tr>
  <tr>
   <th>真实姓名：</th>
   <td><input type="text" name="realname" value="${user.realname}" id="realname"></td>
  </tr>
 <!--   <tr>
   <th width="20%"><span style="color:#ff0000; margin:0;">*</span>请选择角色：</th>
   <td width="80%">
     <select name="roleId">
                            <c:forEach items="${roles}" var="role">
                            <option value="${role.id}" <c:if test='${role.id==user.roleId}'>selected</c:if>>${role.name}</option>
                            </c:forEach>
                            </select>
   </td>
  </tr> --> 
  <tr>
   <th>原密码：</th>
   <td><input type="password" name="yuanPassword" value=""  id="yuanpassword"></td>
  </tr>
  <tr>
   <th>新密码：</th>
   <td><input type="password" name="password" value=""  id="password"></td>
  </tr>
  <tr>
   <th>再次输入新密码：</th>
   <td><input type="password" name="" value="" id="repassword"></td>
  </tr>
  
  <tr>
   <th><span style="color:#ff0000; margin:0;">*</span>选择角色<input type="checkbox" name="" onclick="checkAll(this.checked)">  </th>
   <td>
   <c:forEach items="${roles}" var="role">
   <input type="checkbox" name="ids" value="${role.id}" <c:if test='${fn:contains(user.roleIDS,role.id)}'>checked</c:if>>${role.name}
   </c:forEach>
      
   </td>
  </tr>
 </table>
  <p id="tab_but">
  <input type="hidden" name="id" value="${user.id}">
   <input type="submit" value="提 交">
   <input type="button" value="返回" onclick="history.go(-1)">
   </p>
</form>
</body>
</html>
